<?php
    $i= 1;
    $_total = 0.00;
    $saldo = 0.00;
    $renda = 0.00;
    $custo = 0.00;
    $despesaPaga = 0.00;
    $this->Number->addFormat('BRR',array('before'=>'R$'));
    foreach($accounts as $account):
        foreach($account['Expense'] as $expense):
            $_total = $this->Number->currency($account['Account']['cost'],'');
            if($expense['AccountsExpense']['situation_id']==1){
                $despesaPaga = $despesaPaga + $expense['AccountsExpense']['value'];
            }
            ?>
            <li <?php echo $expense['AccountsExpense']['situation_id']==1? 'class="done"':''?> >
                <div class="check">
                    <input type="checkbox" class="icheck-me" value="<?php echo $expense['AccountsExpense']['value'] ?>" name="data[AccountsExpense][situation_id]" id="sa-checkbox-ItemDespesa<?php echo $i ?>" data-skin="square" data-color="blue" onclick="pagarItemDespesa(<?php echo $i ?>);" data-value="<?php echo $expense['AccountsExpense']['id']; ?>" <?php echo $expense['AccountsExpense']['situation_id']==1? 'checked="checked"':''?> >
                </div>
                <span class="task"><span><?php echo $expense['name'] ?></span> - <?php echo $this->Number->currency($expense['AccountsExpense']['value'],'BRR');?></span>
                <span class="task-actions">
                    <a href="#" class="task-delete" id="sa-link-deleteItemDespesa" onclick="deleteItemDespesa('<?php echo $expense['AccountsExpense']['id'] ?>',<?php echo $i ?>)" rel="tooltip" title="Delete that task"><i class="icon-remove"></i></a>
                </span>
            </li>
            <?php
            $i++;
        endforeach;
    endforeach;
    $custo = $account['Account']['cost'];
    $saldo = $account['Account']['balance'];
    $renda = $account['Account']['income'];
?>
<script type="text/javascript">
    $(document).ready(function(){
        $('#sa-list-ItensDespesa').attr('data-count','<?php echo $i-1; ?>');
        $('#sa-valueTotalDespesa').attr('data-value','');
        // adicionar um valor total para o atributo data-value.
        $('#sa-valueTotalDespesa').attr('data-value',<?php echo $custo; ?>);
        $('#sa-valueTotalDespesa').html('<?php echo $_total ?>');

        $("#sa-li-saldo #value-saldo").html('');
        $("#sa-li-saldo #value-saldo").html('<?php echo $saldo ?>');
        $("#sa-li-saldo #value-saldo").attr('data-value',<?php echo $saldo ?>);

        $("#sa-li-custo #value-custo").html('');
        $("#sa-li-custo #value-custo").html('<?php echo $custo ?>');
        $("#sa-li-custo #value-custo").attr('data-value',<?php echo $custo ?>);

        $("#sa-li-renda #value-renda").html('');
        $("#sa-li-renda #value-renda").html('<?php echo $renda ?>');
        $("#sa-li-renda #value-renda").attr('data-value',<?php echo $renda ?>);

        $("#sa-input-valorRenda").val('');
        $("#sa-input-valorRenda").val(<?php echo $renda ?>);

        $("#sa-select-recipe_id").each(function(){
            var check = $(this).val();
            alert(check);
        });

        $('#sa-valueTotalDespesaPaga').attr('data-value',<?php echo $despesaPaga ?>);
        $('#sa-valueTotalDespesaPaga').html('');
        $('#sa-valueTotalDespesaPaga').html(<?php echo $despesaPaga ?>);
        <?php if($custo == $despesaPaga):?>
            $('#sa-box-verValorDispesa').removeClass('red');
            $('#sa-box-verValorDispesa').addClass('green');
        <?php endif; ?>
    });
</script>